
// initial state
// shape: [{ id, quantity }]
const state = {
  items: []
}

// getters
const getters = {
  getCart: (state) => {
    return state.items
  }
}

// actions
const actions = {
  pushNew ({commit, state}, param) {
    commit('setItem', param)
  },
  changeNewVal ({commit, state}, param) {
    commit('changeItem', param)
  }
}

// mutations
const mutations = {
  setItem (state, param) {
    state.items.push(param)
  },
  changeItem (state, param) {
    var index = state.items.indexOf(param)
    state.items.splice(index, 1, param)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
